package com.sunshuo.springsecuritydemo.controller;

import org.json.JSONObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @ClassName PageController
 * @Description TODO
 * @Author sunshuo
 */
@Controller
@RequestMapping("/menu_page")
public class PageController {

    @PreAuthorize("hasAuthority('1000')")
    @RequestMapping("/menu_1")
    @ResponseBody
    public String menu_1() {
        JSONObject result = new JSONObject();
        result.put("url", "/menu/menu1.jsp");
        return result.toString();
    }

    @PreAuthorize("hasAnyRole('ADMIN', 'DIRECTOR')")
    @RequestMapping("/menu_2")
    @ResponseBody
    public String menu_2() {
        JSONObject result = new JSONObject();
        result.put("url", "/menu/menu2.jsp");
        return result.toString();
    }

    @PreAuthorize("hasAuthority('3000') or hasRole('ADMIN')")
    @RequestMapping("/menu_3")
    @ResponseBody
    public String menu_3() {
        JSONObject result = new JSONObject();
        result.put("url", "/menu/menu3.jsp");
        return result.toString();
    }

    @PreAuthorize("isAuthenticated()")
    @RequestMapping("/menu_4")
    @ResponseBody
    public String menu_4() {
        JSONObject result = new JSONObject();
        result.put("url", "/menu/menu4.jsp");
        return result.toString();
    }

}
